package com.hns.can.report.web;

import java.io.File;
import java.io.FileInputStream;
import java.io.InputStream;
import java.io.OutputStream;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.servlet.ServletRequest;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.commons.net.ftp.FTPClient;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.multipart.MultipartFile;

import com.hns.can.common.domain.GridPage;
import com.hns.can.common.domain.ReturnResult;
import com.hns.can.common.web.BaseController;
import com.hns.can.report.service.DriverBehaviorService;
import com.hns.can.report.vo.DrvBehaviorFeatureDetailVo;
import com.hns.can.report.vo.DrvBehaviorFeatureTypeVo;
import com.hns.can.report.vo.DrvBehaviorFeatureVo;
import com.hns.can.report.vo.DrvBehaviorImproveVo;
import com.hns.can.report.vo.DrvBehaviorScoreAvgVo;
import com.hns.can.report.vo.DrvBehaviorScoreHotVo;
import com.hns.can.report.vo.DrvBehaviorScoreSingleVo;
import com.hns.can.report.vo.DrvBehaviorScoreSortVo;
import com.hns.can.report.vo.DrvBehaviorScoreTrendVo;
import com.hns.can.report.vo.DrvInfoVo;
import com.hns.can.report.vo.TimeRangeVo;
import com.hns.can.upgrade.entity.UpgPhoneParam;
import com.hns.can.upgrade.entity.UpgPhoneVrsn;
import com.hns.can.upgrade.service.UpgPhoneVrsnService;
import com.hns.frame.mybatis.Pagination;
import com.hns.frame.util.BeanUtilsByOverwriteSpring;
import com.hns.tool.pub.DateTool;
import com.hns.tool.pub.FTPUtils;
import com.hns.tool.pub.SAXUtil;
import com.hns.tool.pub.UtilConfig;
import com.hns.tool.pub.UtilString;

/**
 * @ClassName: DriverBehaviorController
 * @Description:
 * @author zhangl
 * @email victor_007@126.com
 * @date 2016年12月14日 下午5:09:55
 */
@Controller
@RequestMapping("driverBehavior")
public class DriverBehaviorController extends BaseController {

    @Autowired
    private DriverBehaviorService driverBehaviorService;

    /**
     * 
     * @Title:  getDrvList
     * @Description: 驾驶员列表
     * @author zhangl
     * @param request
     * @return
     * Object
     */
    @RequestMapping("getDrvList")
    @ResponseBody
    public Object getDrvList(HttpServletRequest request) {
        Map<String, Object> params = getParameter();
        List<DrvInfoVo> dataList = driverBehaviorService.getDrvList(params);
        return new ReturnResult(dataList);
    }

    /**
     * @Title: statBehaviorProportion
     * @Description: 驾驶行为占比
     * @author zhangl
     * @return ReturnResult
     */
    @RequestMapping("statBeorRatioRange")
    @ResponseBody
    public ReturnResult statBehaviorProportion() {
        Map<String, Object> params = getParameter();
        Map<String, Object> map = driverBehaviorService.statBeorRatioRange(params);
        return new ReturnResult(map);
    }

    /**
     * @Title: statScoreLevelRatio
     * @Description: 驾驶员分数等级、比率、平均分、临界点 统计
     * @author zhangl
     * @return ReturnResult
     */
    @RequestMapping("statScoreLevelRatio")
    @ResponseBody
    public ReturnResult statScoreLevelRatio() {
        Map<String, Object> params = getParameter();
        Map<String, Object> map = driverBehaviorService.statScoreLevelRatio(params);
        return new ReturnResult(map);
    }

    /**
     * @Title: statScoreHot
     * @Description: 驾驶员评分热力
     * @author zhangl
     * @return ReturnResult
     */
    @RequestMapping("statScoreHot")
    @ResponseBody
    public ReturnResult statScoreHot() {
        Map<String, Object> params = getParameter();
        Map<String, Object> map = driverBehaviorService.statScoreHot(params);
        return new ReturnResult(map);
    }

    /**
     * @Title: getDrvImproveList
     * @Description: 驾驶员进退步排名
     * @author zhangl
     * @return ReturnResult
     */
    @RequestMapping("getDrvImproveList")
    @ResponseBody
    public ReturnResult getDrvImproveList() {
        Map<String, Object> dataMap = new HashMap<String, Object>();
        Map<String, Object> params = getParameter();
        params.put("dType", 1);
        List<DrvBehaviorImproveVo> dataListPro = driverBehaviorService.getDrvImproveList(params);

        params.put("dType", 2);
        List<DrvBehaviorImproveVo> dataListBac = driverBehaviorService.getDrvImproveList(params);

        dataMap.put("dataListPro", dataListPro);
        dataMap.put("dataListBac", dataListBac);
        return new ReturnResult(dataMap);
    }

    /**
     * @Title: getDrvScoreSortList
     * @Description: 驾驶员评分排名 前5 后5
     * @author zhangl
     * @return ReturnResult
     */
    @RequestMapping("getDrvScoreSortList")
    @ResponseBody
    public ReturnResult getDrvScoreSortList() {
        Map<String, Object> dataMap = new HashMap<String, Object>();
        Map<String, Object> params = getParameter();
        params.put("sortType", "desc");
        List<DrvBehaviorScoreSortVo> dataListDesc = driverBehaviorService.getDrvScoreSortList(params);
        params.put("sortType", "asc");
        List<DrvBehaviorScoreSortVo> dataListAsc = driverBehaviorService.getDrvScoreSortList(params);
        TimeRangeVo timeRangeVo = driverBehaviorService.getTimeRange(params);
        dataMap.put("timeRangeVo", timeRangeVo);
        dataMap.put("dataListAsc", dataListAsc);
        dataMap.put("dataListDesc", dataListDesc);
        return new ReturnResult(dataMap);
    }

    /**
     * @Title: getDrvScoreSortPage
     * @Description: 驾驶员评分排名 分页
     * @author zhangl
     * @return ReturnResult
     */
    @RequestMapping("getDrvScoreSortPage")
    @ResponseBody
    public ReturnResult getDrvScoreSortPage() {
        Map<String, Object> params = getParameter();
        params.put("sortType", "asc");
        Pagination dataPage = driverBehaviorService.getDrvScoreSortPage(params);

        return new ReturnResult(dataPage);
    }

    /**
     * @Title: statBehaviorFeature
     * @Description: 驾驶行为特征待改进 前10
     * @author zhangl
     * @return ReturnResult
     */
    @RequestMapping("statBehaviorFeature")
    @ResponseBody
    public ReturnResult statBehaviorFeature() {
        Map<String, Object> params = getParameter();
        List<DrvBehaviorFeatureVo> dataList = driverBehaviorService.statBehaviorFeature(params);
        return new ReturnResult(dataList);
    }
    
    /**
     * 
     * @Title:  getDrvScoreSortSingle
     * @Description: 单个驾驶员评分
     * @author zhangl
     * @return
     * ReturnResult
     */
    @RequestMapping("getDrvScoreSortSingle")
    @ResponseBody
    public ReturnResult getDrvScoreSortSingle() {
        Map<String, Object> params = getParameter();
        DrvBehaviorScoreSortVo scoreSortVo = driverBehaviorService.getDrvScoreSortSingle(params);
        return new ReturnResult(scoreSortVo);
    }
    
    /**
     * 
     * @Title:  getBehaviorFeatureTypeSingle
     * @Description: 驾驶员驾驶行为画像
     * @author zhangl
     * @return
     * ReturnResult
     */
    @RequestMapping("getBehaviorFeatureTypeSingle")
    @ResponseBody
    public ReturnResult getBehaviorFeatureTypeSingle() {
        Map<String, Object> params = getParameter();
        List<DrvBehaviorFeatureTypeVo> dataList = driverBehaviorService.getBehaviorFeatureType(params);
        return new ReturnResult(dataList);
    }

    /**
     * 
     * @Title:  getBehaviorFeatureDetail
     * @Description: 驾驶员驾驶行为特征明细 
     * @author zhangl
     * @return
     * ReturnResult
     */
    @RequestMapping("getBehaviorFeatureDetail")
    @ResponseBody
    public ReturnResult getBehaviorFeatureDetail() {
        Map<String, Object> params = getParameter();
        List<DrvBehaviorFeatureDetailVo> dataList = driverBehaviorService.getBehaviorFeatureDetail(params);
        return new ReturnResult(dataList);
    }

    /**
     * 
     * @Title:  getBehaviorFeatureCompare
     * @Description: 驾驶员驾驶行为特征比较
     * @author zhangl
     * @return
     * ReturnResult
     */
    @RequestMapping("getBehaviorFeatureCompare")
    @ResponseBody
    public ReturnResult getBehaviorFeatureCompare() {
        Map<String, Object> params = getParameter();
        Map<String, Object> dataMap = driverBehaviorService.getBehaviorFeatureCompare(params);
        return new ReturnResult(dataMap);
    }
    
    /**
     * 
     * @Title:  getBehaviorReport
     * @Description: 驾驶员行为分析报告
     * @author zhangl
     * @return
     * ReturnResult
     */
    @RequestMapping("getBehaviorReport")
    @ResponseBody
    public ReturnResult getBehaviorReport() {
        Map<String, Object> params = getParameter();
        Map<String, Object> dataMap = driverBehaviorService.getBehaviorReport(params);
        return new ReturnResult(dataMap);
    }
    
    /**
     * 
     * @Title:  getBehaviorScoreTrend
     * @Description: 驾驶员分数趋势图
     * @author zhangl
     * @return
     * ReturnResult
     */
    @RequestMapping("getBehaviorScoreTrend")
    @ResponseBody
    public ReturnResult getBehaviorScoreTrend() {
        Map<String, Object> params = getParameter();
        if(params.get("dateType").toString() != null && params.get("dateType").toString().equals("02")){
            params.put("dateType", "03");//将“昨天”强制转为“近7天”
        }
        List<DrvBehaviorScoreTrendVo> dataList = driverBehaviorService.getBehaviorScoreTrend(params);
        return new ReturnResult(dataList);
    }
    
    /**
     * 
     * @Title:  getBehaviorScoreWeek
     * @Description: 驾驶员一周分数
     * @author zhangl
     * @return
     * ReturnResult
     */
    @RequestMapping("getBehaviorScoreWeek")
    @ResponseBody
    public ReturnResult getBehaviorScoreWeek() {
        Map<String, Object> params = getParameter();
        List<DrvBehaviorScoreTrendVo> dataList = driverBehaviorService.getBehaviorScoreWeek(params);
        return new ReturnResult(dataList);
    }
}
